package com.ruoyi.web.controller.file;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.my.service.MyBucketService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@RestController
@RequestMapping("/bucket")
public class MyBucketController extends BaseController {

    @Autowired
    MyBucketService myBucketService;

    /**
     * 获取bucket桶列表
     * @return
     */
    @PreAuthorize("@ss.hasPermi('my:bucket:list')")
    @GetMapping("/list")
    public AjaxResult list(){
        //todo:根据输入从数据库查出相应记录
        return null;
    }

    /**
     * 创建存储Bucket（文件夹）
     * @param bucketName
     * @return
     */
    @PreAuthorize("@ss.hasPermi('my:bucket:add')")
    @PostMapping("/add")
    public AjaxResult add(String bucketName){
        return AjaxResult.success(myBucketService.add(bucketName));
    }

    /**
     * 删除存储bucket，该方法只能删除空文件夹
     * @param bucketName 存储bucket名称
     * @return Boolean
     */
    @PreAuthorize("@ss.hasPermi('my:bucket:remove')")
    @PostMapping("/remove")
    public AjaxResult remove(String bucketName) {
        return AjaxResult.success(myBucketService.remove(bucketName));
    }
}
